Fix several "obvious" memory leaks in various readers. Fallout from our
authorrobertlipe <robertlipe@gmail.com>
Mon, 8 Jul 2013 18:19:15 +0000 (18:19 +0000)
committerrobertlipe <robertlipe@gmail.com>
Mon, 8 Jul 2013 18:19:15 +0000 (18:19 +0000)
half-C/half-QString implementation at this time.

gpsbabel/cet_util.cc
gpsbabel/garmin_txt.cc
gpsbabel/geo.cc
gpsbabel/geoniche.cc
gpsbabel/gpx.cc
gpsbabel/lmx.cc
gpsbabel/maggeo.cc
gpsbabel/navicache.cc
gpsbabel/tmpro.cc
gpsbabel/unicsv.cc

index b86d73f0572c95e604d5b82a2b6afb79b9f96e4b..99ebc296c0323928869c7fd0a6fcb27de7a21f1c 100644 (file)
@@ -1047,15 +1047,25 @@ cet_convert_waypt(const waypoint* wpt)
   w->shortname = cet_convert_string(wpt->shortname);
   w->description = cet_convert_string(wpt->description);
   w->notes = cet_convert_string(wpt->notes);
-  w->url = cet_convert_string(wpt->url);
-  w->url_link_text = cet_convert_string(wpt->url_link_text);
+
+  const char*url = cet_convert_string(wpt->url);
+  const char*url_link_text = cet_convert_string(wpt->url_link_text);
+  w->url = url;
+  w->url_link_text = url_link_text;
+  xfree(url);
+  xfree(url_link_text);
+
   for (url_next = w->url_next; url_next; url_next = url_next->url_next) {
     url_next->url = cet_convert_string(url_next->url);
     url_next->url_link_text = cet_convert_string(url_next->url_link_text);
   }
   if (gc_data) {
-    gc_data->placer = cet_convert_string(gc_data->placer);
-    gc_data->hint = cet_convert_string(gc_data->hint);
+    const char *placer = cet_convert_string(gc_data->placer);
+    const char *hint = cet_convert_string(gc_data->hint);
+    gc_data->placer = placer;
+    gc_data->hint = hint;
+    xfree(placer);
+    xfree(hint);
   }
 
   fs = wpt->fs;
@@ -1082,7 +1092,9 @@ cet_convert_route_hdr(const route_head* route)
 
   rte->rte_name = cet_convert_string(route->rte_name);
   rte->rte_desc = cet_convert_string(route->rte_desc);
-  rte->rte_url = cet_convert_string(route->rte_url);
+  const char*rte_url = cet_convert_string(route->rte_url);
+  rte->rte_url = rte_url;
+  xfree(rte_url);
 }
 
 /* cet_convert_route_tlr: internal used within cet_convert_strings process */
index 88500f68445fa184d50ec3fe8f93284ba12f3e79..01e6bfd53c239bc82d33f573a6f8a55fe63097d7 100644 (file)
@@ -1195,7 +1195,7 @@ parse_waypoint(void)
       }
       break;
     case 17:
-      wpt->url = DUPSTR(str);
+      wpt->url = str;
       break;
     case 18:
       GMSD_SET(category, parse_categories(str));
index 64953d9d75f8b3bc457a62bbfffd90b5ea5575e5..5f15d295b9f9489a84fa2351ed91d614ab6f20ea 100644 (file)
@@ -251,7 +251,7 @@ void wpt_name(const char* args, const char** unused)
   s = xstrrstr(wpt_tmp->description, " by ");
   if (s) {
     waypt_alloc_gc_data(wpt_tmp);
-    wpt_tmp->gc_data->placer = xstrdup(s + 4);
+    wpt_tmp->gc_data->placer = QString(s + 4);
 
     if (nuke_placer) {
       // Sleaze alert.  We're casting away constness and writing into a string
@@ -266,14 +266,14 @@ void wpt_link_s(const char* args, const char** attrv)
   const char** avp = &attrv[0];
   while (*avp) {
     if (0 == strcmp(avp[0], "text")) {
-      wpt_tmp->url_link_text = xstrdup(avp[1]);
+      wpt_tmp->url_link_text = avp[1];
     }
     avp+=2;
   }
 }
 void wpt_link(const char* args, const char** attrv)
 {
-  wpt_tmp->url = xstrdup(args);
+  wpt_tmp->url = args;
 }
 
 void wpt_type(const char* args, const char** unused)
index e2d92d84415efbba400645cfa77d1f3f4746a8e3..35a90eb3c66e18d991cebc843c871c595430309e 100644 (file)
@@ -468,9 +468,6 @@ geoniche_icon_to_descr(const int no)
       result = geoniche_icon_map[i];
     }
   }
-  if (result != NULL) {
-    result = xstrdup(result);
-  }
   return result;
 }
 
index f93ba139f1837e446e156fd2226d15f3d593393f..0f1bcca7bafd602c2350f5c9dc727830f2c6bce0 100644 (file)
@@ -990,7 +990,7 @@ gpx_end(void* data, const XML_Char* xml_el)
   case tt_cache_hint:
     rtrim(cdatastrp);
     if (cdatastrp[0]) {
-      waypt_alloc_gc_data(wpt_tmp)->hint = xstrdup(cdatastrp);
+      waypt_alloc_gc_data(wpt_tmp)->hint = cdatastrp;
     }
     break;
   case tt_cache_desc_long:
@@ -998,7 +998,7 @@ gpx_end(void* data, const XML_Char* xml_el)
     if (cdatastrp[0]) {
       geocache_data* gc_data = waypt_alloc_gc_data(wpt_tmp);
       gc_data->desc_long.is_html = cache_descr_is_html;
-      gc_data->desc_long.utfstring = xstrdup(cdatastrp);
+      gc_data->desc_long.utfstring = cdatastrp;
     }
     break;
   case tt_cache_desc_short:
@@ -1006,7 +1006,7 @@ gpx_end(void* data, const XML_Char* xml_el)
     if (cdatastrp[0]) {
       geocache_data* gc_data = waypt_alloc_gc_data(wpt_tmp);
       gc_data->desc_short.is_html = cache_descr_is_html;
-      gc_data->desc_short.utfstring = xstrdup(cdatastrp);
+      gc_data->desc_short.utfstring = cdatastrp;
     }
     break;
   case tt_cache_terrain:
@@ -1014,7 +1014,7 @@ gpx_end(void* data, const XML_Char* xml_el)
     waypt_alloc_gc_data(wpt_tmp)->terr = x * 10;
     break;
   case tt_cache_placer:
-    waypt_alloc_gc_data(wpt_tmp)->placer = xstrdup(cdatastrp);
+    waypt_alloc_gc_data(wpt_tmp)->placer = cdatastrp;
     break;
   case tt_cache_log_date:
     gc_log_date = xml_parse_time(cdatastrp);
@@ -1179,12 +1179,12 @@ gpx_end(void* data, const XML_Char* xml_el)
   case tt_wpt_url:
   case tt_trk_trkseg_trkpt_url:
   case tt_rte_rtept_url:
-    wpt_tmp->url = xstrdup(cdatastrp);
+    wpt_tmp->url = cdatastrp;
     break;
   case tt_wpt_urlname:
   case tt_trk_trkseg_trkpt_urlname:
   case tt_rte_rtept_urlname:
-    wpt_tmp->url_link_text = xstrdup(cdatastrp);
+    wpt_tmp->url_link_text = cdatastrp;
     break;
   case tt_wpt_link:
 //TODO: implement GPX 1.1      case tt_trk_trkseg_trkpt_link:
index c46e50bc00636c8669ad2d37b5e3e81dcbd35524..3e0ed4b445dfaf565887eaab76e500d763eda132 100644 (file)
@@ -31,7 +31,8 @@
 
 static gbfile* ofd;
 static waypoint* wpt_tmp;
-char* urllink, *urllinkt;
+QString urllink;
+QString urllinkt;
 static char* binary = NULL;
 
 #define MYNAME "lmx"
@@ -376,19 +377,19 @@ lmx_lm_desc(const char* args, const char** unused)
 static void
 lmx_lm_mlink_s(const char* args, const char** unused)
 {
-  urllink = urllinkt = NULL;
+  urllink = urllinkt = QString();
 }
 
 static void
 lmx_lm_link(const char* args, const char** unused)
 {
-  urllink = xstrdup(args);
+  urllink = args;
 }
 
 static void
 lmx_lm_linkt(const char* args, const char** unused)
 {
-  urllinkt = xstrdup(args);
+  urllinkt = args;
 }
 
 static void
index 996ad151666d651a7a9c21e90e2d8b024172025b..fda2a439d3dc0214ef30e45b59dc98500348f0a5 100644 (file)
@@ -142,10 +142,10 @@ maggeo_read(void)
         wpt_tmp->description = xstrdup(s);
         break;
       case 10:
-        gcdata->placer = xstrdup(s);
+        gcdata->placer = s;
         break;
       case 11:
-        gcdata->hint = xstrdup(s);
+        gcdata->hint = s;
         break;
       case 12: // cache type
         if (strcmp(s, "Mystery Cache") == 0) {
index f530b56788f4519d8e1773469aae4b4c52895e3b..3bf337a99605e5f400bd2f404afade862a3dbc94 100644 (file)
@@ -133,7 +133,7 @@ nav_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr)
       } else if (0 == strcmp(ap[0], "name")) {
         wpt_tmp->description = xstrdup(ap[1]);
       } else if (0 == strcmp(ap[0], "user_name")) {
-        gc_data->placer = xstrdup(ap[1]);
+        gc_data->placer = ap[1];
       } else if (0 == strcmp(ap[0], "latitude")) {
         sscanf(ap[1], "%lf",
                &wpt_tmp->latitude);
@@ -187,10 +187,10 @@ nav_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr)
         gc_data->container = nc_mkcont(ap[1]);
       }  else if (0 == strcmp(ap[0], "description")) {
         gc_data->desc_long.is_html = 1;
-        gc_data->desc_long.utfstring = xstrdup(ap[1]);
+        gc_data->desc_long.utfstring = ap[1];
       } else if (0 == strcmp(ap[0], "comments")) {
         gc_data->desc_short.is_html = 1;
-        gc_data->desc_short.utfstring = xstrdup(ap[1]);
+        gc_data->desc_short.utfstring = ap[1];
       }
     }
     waypt_add(wpt_tmp);
index df7d9f39d99ad1e5f217e8dec09b059337bd9942..a0bbf1e3bd43ccb67004e6e02851224893e9bafe 100644 (file)
@@ -144,9 +144,8 @@ data_read(void)
           holder = csv_stringtrim(s, "", 0);
           if (strstr(holder, "http:") != NULL) {
             wpt_tmp->url = holder;
-          } else {
-            xfree(holder);
-          }
+          } 
+          xfree(holder);
           break;
         default:
           /* whoa! nelly */
index 7b6de5f67a6a97ee98aa125a2a87bf2b6749d3fd..3086d1bd8580e00944991462a59e0a5626c2c1a8 100644 (file)
@@ -1116,13 +1116,13 @@ unicsv_parse_one_line(char *ibuf)
       }
       break;
       case fld_gc_placer:
-        gc_data->placer = xstrdup(s);
+        gc_data->placer = s;
         break;
       case fld_gc_placer_id:
         gc_data->placer_id = atoi(s);
         break;
       case fld_gc_hint:
-        gc_data->hint = xstrdup(s);
+        gc_data->hint = s;
         break;
 
       default: